home *** CD-ROM | disk | FTP | other *** search
/ HPAVC / HPAVC CD-ROM.iso / SCROOL.ZIP / SCREEN.PAS
Pascal/Delphi Source File  |  1996-09-26  |  5KB  |  198 lines

  1. {
  2. I am new to this echo, so here is my offering placed upon
  3. the alter of exceptence. I have seen a couple of requests
  4. for help with both scrolling the screen, as well as
  5. reading/writting directly to/from the screen.
  6.  
  7. Here is a unit to do both. One note here, this unit is
  8. assuming a color monitor. It can be used for a (Barrrrrfffffff)
  9. monocrome monitor by changing the value of
  10. "cscreen to $B000 : $0000"
  11.  
  12. If anyone has any questions, I will be monitoring this echo
  13. from now on and will be happy to answer any questions.
  14.  
  15.  
  16.                                         Robert Long....
  17.  
  18.    -------------------------[ Cut Here ]--------------------------
  19. }
  20.  
  21. Unit screen;
  22.  
  23. INTERFACE
  24.  
  25.     Uses  dos, crt;
  26.  
  27.     Type
  28.        scrp = ^scr;
  29.         scr = array[1..25,1..80] of record
  30.                                       ch : char;
  31.                                       at : byte;
  32.                                     end;
  33.  
  34. { SCRP : Pointer to a screen record. Used to overlay video
  35.          memory, and so you can create dynamic screens on
  36.          the heap.
  37.   SCR :  An array of records that duplicates the video memory.
  38.          You can read any position on the screen like this:
  39.              Character_on_screen:= cscreen[y,x].ch;
  40.          And write to a screen position like this:
  41.           cscreen[y,x].ch:= Character_to_put_on_screen;
  42.          And of course the color attributes would be:
  43.             Attribute_on_screen:= cscreen[y,x].at;
  44. }
  45.  
  46.     Var
  47.       cscreen : scr absolute $b800 : $0000;
  48.  
  49. { Cscreen is overlaied on video memory, so it requires ZERO bytes
  50.   of memory. This means what is on the screen is whats in the record
  51.   and vica/versa. What you write to the record is on the screen as
  52.   fast as the refresh rate of your monitor.
  53. }
  54.  
  55. procedure setscrl(x1,y1,x2,y2 : byte);
  56. procedure getscrl(var x1,y1,x2,y2 : byte);
  57. procedure scrlup(b,f : byte);
  58. procedure scrldn(b,f : byte);
  59. procedure scrll(b,f : byte);
  60. procedure scrlr(b,f : byte);
  61.  
  62.  
  63. IMPLEMENTATION
  64.  
  65.     const
  66.        setscrlx1 : byte = 1;
  67.        setscrly1 : byte = 1;
  68.        setscrlx2 : byte = 80;
  69.        setscrly2 : byte = 25;
  70.  
  71.     var
  72.       reg : registers;
  73.  
  74. { The setscrl routine is just for convience. As the routines
  75.   below will expect the upper-left and lower-right corners
  76.   of your scroll window, why not set them once insted of
  77.   every time you call the routine. As they are typed constants
  78.   (see above) the defult window size (in 25X80 mode) is full
  79.   screen, but can be set to any size.
  80. }
  81.  
  82. procedure setscrl(x1,y1,x2,y2 : byte);
  83.  
  84.     begin
  85.       setscrlx1:= x1;
  86.       setscrly1:= y1;
  87.       setscrlx2:= x2;
  88.       setscrly2:= y2;
  89.     end;
  90.  
  91. { Getscrl is used to get the current scroll window size }
  92.  
  93.  
  94. procedure getscrl(var x1,y1,x2,y2 : byte);
  95.  
  96.     begin
  97.       x1:= setscrlx1;
  98.       y1:= setscrly1;
  99.       x2:= setscrlx2;
  100.       y2:= setscrly2;
  101.     end;
  102.  
  103. { Scrlup will scroll the scroll window (defigned by setscrl) up
  104.   one line. The passed parameters "b" and "f" are the background
  105.   and foreground colors to set the now blank line at the bottom
  106.   of the scroll window.
  107.  }
  108.  
  109.  
  110. procedure scrlup(b,f : byte);
  111.  
  112.     begin
  113.       with reg do
  114.      begin
  115.       ah:= 6;
  116.       al:= 1;
  117.       bh:= ((b and 7) * 16) + (f and 15);
  118.       ch:= setscrly1 - 1; cl:= setscrlx1 - 1;
  119.       dh:= setscrly2 - 1; dl:= setscrlx2 - 1;
  120.      end;
  121.       intr(16,reg);
  122.     end;
  123.  
  124. { Scrldn will scroll the scroll window (defigned by setscrl) down
  125.   one line. The passed parameters "b" and "f" are the background
  126.   and foreground colors to set the now blank line at the top of
  127.   the scroll window.
  128.  }
  129.  
  130. procedure scrldn(b,f : byte);
  131.  
  132.     begin
  133.       with reg do
  134.      begin
  135.       ah:= 7;
  136.       al:= 1;
  137.       bh:= ((b and 7) * 16) + (f and 15);
  138.       ch:= setscrly1 - 1; cl:= setscrlx1 - 1;
  139.       dh:= setscrly2 - 1; dl:= setscrlx2 - 1;
  140.      end;
  141.       intr(16,reg);
  142.     end;
  143.  
  144. { Scrll will scroll the scroll window (defigned by setscrl) left
  145.   one line. The passed parameters "b" and "f" are the background
  146.   and foreground colors to set the now blank line at the left of
  147.   the scroll window.
  148.  }
  149.  
  150. procedure scrll(b,f : byte);
  151.  
  152.     var
  153.       x,y : byte;
  154.  
  155.     begin
  156.       for y:= setscrly1 to setscrly2 do
  157.       for x:= setscrlx1 to setscrlx2 - 1 do
  158.      begin
  159.       cscreen[y,x].at:= cscreen[y,x + 1].at;
  160.       cscreen[y,x].ch:= cscreen[y,x + 1].ch;
  161.      end;
  162.  
  163.       for y:= setscrly1 to setscrly2 do
  164.      begin
  165.       cscreen[y,setscrlx2].at:= b * 16 + f;
  166.       cscreen[y,setscrlx2].ch:= #32;
  167.      end;
  168.     end;
  169.  
  170. { Scrlr will scroll the scroll window (defigned by setscrl) rigth
  171.   one line. The passed parameters "b" and "f" are the background
  172.   and foreground colors to set the now blank line at the right of
  173.   the scroll window.
  174.  }
  175.  
  176. procedure scrlr(b,f : byte);
  177.  
  178.     var
  179.       x,y : byte;
  180.  
  181.     begin
  182.       for y:= setscrly1 to setscrly2 do
  183.       for x:= setscrlx2 downto setscrlx1 + 1 do
  184.      begin
  185.       cscreen[y,x].at:= cscreen[y,x - 1].at;
  186.       cscreen[y,x].ch:= cscreen[y,x - 1].ch;
  187.      end;
  188.  
  189.       for y:= setscrly1 to setscrly2 do
  190.      begin
  191.       cscreen[y,setscrlx1].at:= b * 16 + f;
  192.       cscreen[y,setscrlx1].ch:= #32;
  193.      end;
  194.     end;
  195.  
  196.  
  197. end.
  198.